<template>
    <div v-if="show">
      <Modal :closable="closable" class="modal-title-layout" v-model="show" :title="title || $t('提示')">
        <div class="icon red" :class="{red: type==='delete',yellow:type==='warn',blue:type==='sure'}">
          <i v-if="type==='delete'" class="iconfont zy-common-shanchu"></i>
          <i v-if="type==='sure'" class="iconfont zy-common-chenggong1"></i>
          <i v-if="type==='warn'" class="iconfont zy-common-yichang"></i>
        </div>
        <p class="title">
          <span>{{ desc }}</span>
        </p>
        <div slot="footer" v-show="showFooter">
          <Button type="default" v-if="showCancel" @click="onCancel">{{ $t('common.Cancle') }}</Button>
          <Button type="primary" @click="onSubmit">{{ $t('maintenance.Confirmed') }}
          </Button>
        </div>
      </Modal>
    </div>
</template>

<script>
export default {
    name: "deleteModal",
    props: {
        submit: {
            type: Function,
            default: () => {
            }
        },
        cancel: {
            type: Function,
            default: () => {
            }
        },
        showCancel: {
            type: Boolean,
            default: true
        },
        closable: {
            type: Boolean,
            default: true
        }
    },
    data() {
        return {
            title: "",
            show: false,
            type: "",
            desc:"",
            showFooter:true,
        }
    },
    methods: {
        showModal(obj) {
            this.show = true;
            if (obj) {
                const {submit, type,desc,title,showFooter} = obj
                this.type = type
                this.desc = desc
                this.title = title
                this.showFooter = showFooter==false?false:true
                if (submit && typeof submit === "function") {
                    this.onSubmit = () => {
                        this.show = false
                        submit()
                    }
                }
            }
        },
        onSubmit() {
            if (this.submit) {
                this.$emit('submit')
                this.show = false
            }
        },
        onCancel() {
            if (this.cancel) {
                this.$emit('cancel')
            }
            this.show = false

        },
    }
}
</script>

